package it.mauriziobasile.sincrodir.entita;

import java.io.IOException;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

public class GestoreRisorse {
    private static ResourceBundle risorse;
    private static Properties propieta;
    private static GestoreRisorse instanza;
    
    private GestoreRisorse(){
        
    }
    
    public static GestoreRisorse instanza(){
        if (instanza==null)
            instanza=new GestoreRisorse();
        return instanza;
    }
    
    public ResourceBundle getRisorse(){
        return getRisorse(Locale.getDefault());
    }
    
    public ResourceBundle getRisorse(Locale loc){
        if (risorse==null || !risorse.getLocale().equals(loc))
            risorse=ResourceBundle.getBundle("TextBundle", loc, this.getClass().getClassLoader());
        return risorse;
    }
    

    public Properties getPropieta(){
        if (propieta==null){
            propieta=new Properties();
            try {
                propieta.load(this.getClass().getClassLoader().getResourceAsStream("config.properties"));
            } catch (IOException e) {
                //Non faccio nulla, prometto di mettere sempre il default quando invoco il getProperty
            }
        }
        return propieta;
    }
}
